package stack

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)
// 将栈顶指针复制一份，并压栈
type DUP struct {
	base.NoOperandsInstruction
}
// 弹出一个，然后压入两次，相当于复制一次
func (self *DUP) Execute(frame *runtime_area.Frame) {
	slot := frame.OperandStack().PopSlot()
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
}

// 复制栈顶数值并将两个复制值推入栈顶
type DUP_X1 struct {
	base.NoOperandsInstruction
}

func (self *DUP_X1) Execute(frame *runtime_area.Frame) {
	slot := frame.OperandStack().PopSlot()
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
}


type DUP_X2 struct {
	base.NoOperandsInstruction
}

// 复制栈顶数值并将三个复制值推入栈顶
func (self *DUP_X2) Execute(frame *runtime_area.Frame) {
	slot := frame.OperandStack().PopSlot()
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
	frame.OperandStack().PushSlot(slot)
}
